placesview: List only available protocols as available
authorAntónio Fernandes <antoniof@gnome.org>
Sat, 24 Nov 2018 01:49:43 +0000 (01:49 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 14 Dec 2018 17:30:52 +0000 (12:30 -0500)
We display a list of supported protocols in the server_addresses_popover.

However, this curated list contains protocols which may or may not be
available, depending on the respective gvfs backend being installed.

So, populate the list only with protocols which are available.

https://gitlab.gnome.org/GNOME/gtk/issues/1476

gtk/gtkplacesview.c
gtk/ui/gtkplacesview.ui

index be0a84ab15584cb4d5fd99af30b67575d252a9a8..88975e641258df72d3c359f3a50859c156b67ecf 100644 (file)
@@ -74,6 +74,7 @@ struct _GtkPlacesViewPrivate
   GtkWidget                     *recent_servers_stack;
   GtkWidget                     *stack;
   GtkWidget                     *server_adresses_popover;
+  GtkWidget                     *available_protocols_grid;
   GtkWidget                     *network_placeholder;
   GtkWidget                     *network_placeholder_label;
 
@@ -1583,6 +1584,54 @@ unmount_cb (GtkMenuItem      *item,
   unmount_mount (GTK_PLACES_VIEW (view), mount);
 }
 
+static void
+attach_protocol_row_to_grid (GtkGrid     *grid,
+                             const gchar *protocol_name,
+                             const gchar *protocol_prefix)
+{
+  GtkWidget *name_label;
+  GtkWidget *prefix_label;
+
+  name_label = gtk_label_new (protocol_name);
+  gtk_widget_set_halign (name_label, GTK_ALIGN_START);
+  gtk_grid_attach_next_to (grid, name_label, NULL, GTK_POS_BOTTOM, 1, 1);
+
+  prefix_label = gtk_label_new (protocol_prefix);
+  gtk_widget_set_halign (prefix_label, GTK_ALIGN_START);
+  gtk_grid_attach_next_to (grid, prefix_label, name_label, GTK_POS_RIGHT, 1, 1);
+}
+
+static void
+populate_available_protocols_grid (GtkGrid *grid)
+{
+  const gchar* const *supported_protocols;
+
+  supported_protocols = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
+
+  if (g_strv_contains (supported_protocols, "afp"))
+    attach_protocol_row_to_grid (grid, _("AppleTalk"), "afp://");
+
+  if (g_strv_contains (supported_protocols, "ftp"))
+    /* Translators: do not translate ftp:// and ftps:// */
+    attach_protocol_row_to_grid (grid, _("File Transfer Protocol"), _("ftp:// or ftps://"));
+
+  if (g_strv_contains (supported_protocols, "nfs"))
+    attach_protocol_row_to_grid (grid, _("Network File System"), "nfs://");
+
+  if (g_strv_contains (supported_protocols, "smb"))
+    attach_protocol_row_to_grid (grid, _("Samba"), "smb://");
+
+  if (g_strv_contains (supported_protocols, "ssh"))
+    /* Translators: do not translate sftp:// and ssh:// */
+    attach_protocol_row_to_grid (grid, _("SSH File Transfer Protocol"), _("sftp:// or ssh://"));
+
+  if (g_strv_contains (supported_protocols, "dav"))
+    /* Translators: do not translate dav:// and davs:// */
+    attach_protocol_row_to_grid (grid, _("WebDAV"), _("dav:// or davs://"));
+
+  gtk_widget_show_all (GTK_WIDGET (grid));
+}
+
 /* Constructs the popup menu if needed */
 static void
 build_popup_menu (GtkPlacesView    *view,
@@ -2257,6 +2306,7 @@ gtk_places_view_class_init (GtkPlacesViewClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkPlacesView, recent_servers_stack);
   gtk_widget_class_bind_template_child_private (widget_class, GtkPlacesView, stack);
   gtk_widget_class_bind_template_child_private (widget_class, GtkPlacesView, server_adresses_popover);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkPlacesView, available_protocols_grid);
 
   gtk_widget_class_bind_template_callback (widget_class, on_address_entry_text_changed);
   gtk_widget_class_bind_template_callback (widget_class, on_address_entry_show_help_pressed);
@@ -2285,6 +2335,8 @@ gtk_places_view_init (GtkPlacesView *self)
   gtk_widget_add_controller (GTK_WIDGET (self), controller);
 
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  populate_available_protocols_grid (GTK_GRID (priv->available_protocols_grid));
 }
 
 /*
index 48db836e5dca37dc7e9b793cb60d76a785e929b1..93324924c4407a58d9c52a64b317bf3af30cef32 100644 (file)
@@ -61,7 +61,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkGrid">
+          <object class="GtkGrid" id="available_protocols_grid">
             <property name="margin-top">12</property>
             <property name="hexpand">1</property>
             <property name="row-spacing">6</property>
                 <property name="top-attach">0</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">AppleTalk</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">File Transfer Protocol</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">Network File System</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">3</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">Samba</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">4</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">SSH File Transfer Protocol</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">5</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">WebDAV</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">6</property>
-              </packing>
-            </child>
             <child>
               <object class="GtkLabel">
                 <property name="label" translatable="yes">Prefix</property>
                 <property name="top-attach">0</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label">afp://</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes" comments="Translators: do not translate ftp:// and ftps://">ftp:// or ftps://</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label">nfs://</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">3</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">smb://</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">4</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes" comments="Translators: do not translate sftp:// and ssh://">sftp:// or ssh://</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">5</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes" comments="Translators: do not translate dav:// and davs://">dav:// or davs://</property>
-                <property name="xalign">0</property>
-              </object>
-              <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">6</property>
-              </packing>
-            </child>
           </object>
           <packing>
             <property name="position">3</property>